<template>
	<VerticalSplitLayout :topHeight="375">
		<template #top>
			<div class=" layout-padding-view overflow-x-hidden pb-1.5 pr-1.5" style="overflow-y: auto; height: auto">
				<!--基础信息-->
				<el-row >
					<el-col :span="3" class="flex flex-col justify-center items-center border-r-4  ">
            <img src="/@/assets/icons/info01.svg" style="width: 80px;height: 80px;transform: rotate(120deg);" />
						<el-text  type="primary" class="font-black "  style="font-size: 18px">{{ $t('iot.basInfo') }}</el-text>
					</el-col>
					<el-col :span="21" class="pt-2">
						<el-form :model="dataForm" :rules="dataRules" ref="queryRef2" :inline="true" label-position="right" label-width="120">
							<el-row>
								<el-col :span="6">
									<el-form-item :label="$t('iot.processCode')" prop="processCode" style="width: 100%">
										<el-select
											filterable
											remote
											@change="changeProcess"
											style="width: 100%"
											:remote-method="getProcess"
											v-model="dataForm.processCode"
										>
											<el-option v-for="item in processList" :key="item.processCode" :label="item.processCode" :value="item">
												<span style="float: left">{{ item.processCode }}</span>
												<span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{ item.processName }} </span>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.processName')" prop="processName" style="width: 100%">
										<el-select filterable remote style="width: 100%" disabled v-model="dataForm.processName"> </el-select>
									</el-form-item>
								</el-col>

								<el-col :span="6">
									<el-form-item :label="$t('iot.productionLineCode')" prop="productionLineCode" style="width: 100%">
										<el-select
											filterable
											remote
											@change="changeProductionLine"
											:remote-method="getProductionline"
											style="width: 100%"
											v-model="dataForm.productionLineCode"
										>
											<el-option style="width:240px" v-for="item in Productionlinelist" :key="item.productionLineCode" :label="item.productionLineCode" :value="item">
												<span style="float: left">{{ item.productionLineCode }}</span>
												<span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{ item.productionLineName }} </span>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.productionLineName')" prop="productionLineName" style="width: 100%">
										<el-select filterable remote style="width: 100%" disabled v-model="dataForm.productionLineName"> </el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="6">
									<el-form-item :label="$t('iot.locationCode')" :prop="locationShow ? 'locationCode' : ''" v-show="locationShow" style="width: 100%">
										<el-select
											filterable
											remote
											@change="changeLocation"
											:remote-method="getLocation"
											style="width: 100%"
											v-model="dataForm.locationCode"
										>
											<el-option style="width:540px" v-for="item in LocationList" :key="item.locationCode" :label="item.locationCode" :value="item">
												<span style="float: left">{{ item.locationCode }}</span>
												<span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{ item.locationName }} </span>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.locationName')" prop="locationName" v-show="locationShow" style="width: 100%">
										<el-select filterable remote disabled style="width: 100%" v-model="dataForm.locationName"> </el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.locationTypeName')" prop="locationTypeName" v-show="locationShow" style="width: 100%">
										<el-select filterable remote disabled style="width: 100%" v-model="dataForm.locationTypeName"> </el-select> </el-form-item
								></el-col>
							</el-row>
							<el-row>
								<el-col :span="6">
									<el-form-item :label="$t('iot.materialCode')" :prop="materialShow ? 'materialCode' : ''" v-show="materialShow" style="width: 100%">
									  <MaterialSelect @change="changeMaterial" v-model="dataForm.materialCode"/>
										<!--<el-select-->
										<!--	filterable-->
										<!--	remote-->
										<!--	@change="changeMaterial"-->
										<!--	:remote-method="getMaterial"-->
										<!--	style="width: 100%"-->
										<!--	v-model="dataForm.materialCode"-->
										<!--&gt;-->
										<!--	<el-option v-for="item in materialList" :key="item.materialCode" :label="item.materialCode" :value="item">-->
										<!--		<span style="float: left">{{ item.materialCode }}</span>-->
										<!--		<span style="float: right; color: var(&#45;&#45;el-text-color-secondary); font-size: 13px"> {{ item.materialName }} </span>-->
										<!--	</el-option>-->
										<!--</el-select>-->
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.materialName')" prop="materialName" v-show="materialShow" style="width: 100%">
										<el-select filterable remote disabled style="width: 100%" v-model="dataForm.materialName"> </el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.qty')" :prop="materialShow ? 'qty' : ''" style="width: 100%" v-show="materialShow">
										<el-input v-model="dataForm.qty" style="width: 100%" :placeholder="$t('iot.qty')" />
									</el-form-item>
								</el-col>
							</el-row>
						</el-form>
					</el-col>
				</el-row>
				<!--分割线-->
				<el-divider style="margin: 0" border-style="dashed"/>
				<!--产出信息-->
				<el-row >
					<el-col :span="3" class="flex flex-col justify-center items-center border-r-4">
            <img src="/@/assets/icons/warehouse01.svg" style="width: 80px;height: 80px;"  />
						<el-text class="font-black"  type="success" size="large" style="font-size: 18px">{{ $t('iot.outInfo') }}</el-text>
					</el-col>
					<el-col :span="21" class="pt-2">
						<!--表单-->
						<el-form :model="dataForm" :rules="dataRules" ref="queryRef" :inline="true" label-position="right" label-width="120">
							<el-row>
								<el-col :span="6">
									<el-form-item :label="$t('iot.startTime')" prop="startTime" style="width: 100%">
										<el-date-picker
											v-model="dataForm.startTime"
											type="datetime"
											style="width: 100%"
											placeholder="Select date and time"
											format="YYYY/MM/DD HH:mm:ss"
											value-format="YYYY/MM/DD HH:mm:ss"
											:shortcuts="shortcuts"
										/>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.endTime')" prop="endTime" style="width: 100%">
										<el-date-picker
											v-model="dataForm.endTime"
											type="datetime"
											style="width: 100%"
											placeholder="Select date and time"
											:shortcuts="shortcuts"
											format="YYYY/MM/DD HH:mm:ss"
											value-format="YYYY/MM/DD HH:mm:ss"
										/>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.operationType')" prop="operationType" style="width: 100%">
										<el-select filterable remote @change="changeOperationType" style="width: 100%" v-model="dataForm.operationType">
											<el-option v-for="item in operationTypelist" :key="item.itemCode" :label="item.itemCode" :value="item">
												<span style="float: left">{{ item.itemCode }}</span>
												<span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{ item.itemText }} </span>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.lotNo')" prop="lotNo" style="width: 100%; margin-bottom: 0 !important">
										<el-input disabled v-model="dataForm.lotNo" :placeholder="$t('iot.lotNo')" />
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="6">
									<el-form-item :label="$t('iot.palletNumber')" prop="palletNumber"style="width: 100%" >
										<el-input v-model="dataForm.palletNumber" :placeholder="$t('iot.palletNumber')" />
									</el-form-item>
								</el-col>

								<el-col :span="6">
									<el-form-item :label="$t('iot.unit')" prop="unit" style="width: 100%; margin-bottom: 0 !important">
										<el-select v-model="dataForm.unit" filterable placeholder="Select Unit" style="width: 100%">
											<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="6">
									<el-form-item :label="$t('iot.operationDescription')" prop="operationDescription" style="width: 100%">
										<el-select filterable remote @change="changeOperationDescription" v-model="dataForm.operationDescription" style="width: 100%">
											<el-option v-for="item in operationDescriptionlist" :key="item.itemCode" :label="item.itemCode" :value="item">
												<span style="float: left">{{ item.itemCode }}</span>
												<span style="float: right; color: var(--el-text-color-secondary); font-size: 13px"> {{ item.itemText }} </span>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="12">
									<el-form-item :label="$t('iot.isCurrentLocation')" prop="isCurrentLocation">
										<el-switch v-model="isCurrentLocation" class="" v-show="isCurrentLocationShow" />
									</el-form-item>
									<el-form-item :label="$t('iot.isWarp')" prop="isWarp">
										<el-switch style="" v-model="isWarp" class="" v-show="isWarpBandShow" />
									</el-form-item>
									<el-form-item :label="$t('iot.isBand')" prop="isBand">
										<el-switch style="" v-model="isBand" class="" v-show="isWarpBandShow" />
									</el-form-item>
								</el-col>

							</el-row>

						</el-form>
					</el-col>
				</el-row>

        <el-divider style="margin: 0 " border-style="dashed"/>
        <el-row class="pt-3">
          <el-col :offset="3" class="">
            <el-button class="" icon="el-icon-plus" type="primary" @click="addData">
              {{ $t('operation.add') }}
            </el-button>
            <el-button icon="refresh" @click="resetQuery">{{ $t('storageInfo.reset') }}</el-button>
          </el-col>

        </el-row>
			</div>

		</template>
		<template #bottom>
        <el-tabs model-value="first" class="card-tabs" type="border-card">
          <el-tab-pane name="first">
            <template #label>
							<span class="ml-0.5">
								{{ $t('iot.dataList') }}
							</span>
            </template>
            <div class="layout-padding-auto">
              <el-form>
                <el-form-item>
                  <el-button icon="Check" type="primary" @click="save(selectObjs)">
                    {{ $t('btn.save') }}
                  </el-button>
                  <el-button icon="el-icon-delete" type="danger" @click="handleDelete(selectObjs)">{{ $t('btn.delete') }}</el-button>
                </el-form-item>
              </el-form>

              <!--查询结果的列表-->
              <el-table
                  :data="state.dataList"
                  v-loading="state.loading"
                  border
                  :cell-style="tableStyle.cellStyle"
                  style="width: 100%; height: 100%"
                  :header-cell-style="tableStyle.headerCellStyle"
                  stripe
                  @sort-change="sortChangeHandle"
                  @selection-change="selectionChangeHandle"
              >
                <el-table-column type="selection" width="40" align="center" />
                <el-table-column type="index" label="#" width="50" />
                <el-table-column prop="processCode" :label="$t('iot.processCode')" width="120" />
                <el-table-column prop="processName" :label="$t('iot.processName')" width="120" />
                <el-table-column prop="productionLineCode" :label="$t('iot.productionLineCode')" width="220" />
                <el-table-column prop="productionLineName" :label="$t('iot.productionLineName')" width="180" />
                <el-table-column prop="locationCode" :label="$t('iot.locationCode')" width="180" />
                <el-table-column prop="locationName" :label="$t('iot.locationName')" width="250" />
                <el-table-column prop="locationTypeName" :label="$t('iot.locationTypeName')" width="160" />
                <el-table-column prop="materialCode" :label="$t('iot.materialCode')" width="140" />
                <el-table-column prop="materialName" :label="$t('iot.materialName')" width="200" />
                <el-table-column prop="qty" :label="$t('iot.qty')" width="80" />
                <el-table-column prop="startTime" :label="$t('iot.startTime')" width="160" />
                <el-table-column prop="endTime" :label="$t('iot.endTime')" width="160" />
                <el-table-column prop="lotNo" :label="$t('iot.lotNo')" width="70" />
                <el-table-column prop="operationType" :label="$t('iot.operationType')" width="200" />
                <el-table-column prop="operationDescription" :label="$t('iot.operationDescription')" width="200" />
                <el-table-column prop="unit" :label="$t('iot.unit')" width="70" />
                <el-table-column prop="palletNumber" :label="$t('iot.palletNumber')" width="200" />
              </el-table>
              <pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
            </div>
          </el-tab-pane>
        </el-tabs>
		</template>
	</VerticalSplitLayout>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue';
import { BasicTableProps, useTable } from '/@/hooks/table';
import { getAllProcess } from '/@/api/platform/wms/reprintbarcode';
import { getAllProductionlineByProcess, getBaseData, getDic, iOTOutputDataEntry } from '/@/api/platform/mes/iot';
import { getAllMaterialsForNameOrCode, getProcessLocationByPrdLineId } from '/@/api/platform/digital/basProcess';
import { useMessage } from '/@/hooks/message';
import { useI18n } from 'vue-i18n';
import VerticalSplitLayout from '/@/components/VerticalSplitLayout/index.vue';
import MaterialSelect from "/@/components/mes/select/MaterialSelect.vue";

const { t } = useI18n();
const size = ref(50);
const queryRef = ref();
const queryRef2 = ref();
const processList = ref();
const Productionlinelist = ref();
const LocationList = ref();
const materialList = ref();
const operationTypelist = ref();
const operationDescriptionlist = ref();
const materialShow = ref(true);
const locationShow = ref(true);
const smallDatalist = ref([]); //小料
const otherDatalist = ref([]); //停机，试机，主料预混
const isCurrentLocation = ref(false);
const isWarp = ref(false);
const isBand = ref(false);
const isCurrentLocationShow = ref(true);
const isWarpBandShow = ref(true);

//加载操作类型和操作描述
onMounted(() => {
	getDic().then((res: { result: { operationTypeList: any; operationTypeDescList: any } }) => {
		operationTypelist.value = res.result.operationTypeList;
		operationDescriptionlist.value = res.result.operationTypeDescList;
	});
});

const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: '',
});

//时间选择器
const shortcuts = [
	{
		text: 'Today',
		value: new Date(),
	},
	{
		text: 'Yesterday',
		value: () => {
			const date = new Date();
			date.setDate(date.getDate() - 1);
			return date;
		},
	},
	{
		text: 'A week ago',
		value: () => {
			const date = new Date();
			date.setDate(date.getDate() - 7);
			return date;
		},
	},
];
//单位
const options = [
	{
		value: 'Pcs',
		label: 'Pcs',
	},
	{
		value: 'box',
		label: 'box',
	},
	{
		value: 'LBS',
		label: 'LBS',
	},
	{
		value: 'kg',
		label: 'kg',
	},
	{
		value: 'zhang',
		label: 'zhang',
	},
	{
		value: 'ge',
		label: 'ge',
	},
	{
		value: 'pingfang',
		label: 'pingfang',
	},
];

//表单对象
const dataForm = reactive({
	processCode: '',
	processName: '',
	processid: '',
	productionLineCode: '',
	productionLineName: '',
	productionLinId: '',
	locationCode: '',
	locationName: '',
	locationTypeName: 'PDLocation',
	materialCode: '',
	materialName: '',
	qty: '',
	startTime: '',
	endTime: '',
	lotNo: '',
	operationType: '',
	operationDescription: '',
	unit: '',
	palletNumber: '',
	id: '',
	uuid: '',
	isCurrentLocation: 'N',
	isWarp: 'N',
	isBand: 'N',
});
dataForm.lotNo = 1;

// 定义表单校验规则
const dataRules = reactive({
	processCode: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	productionLineCode: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	materialCode: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	qty: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	locationCode: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	startTime: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	endTime: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	lotNo: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	operationType: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	operationDescription: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
	unit: [{ required: true, message: t('iot.requiredFields'), trigger: 'blur' }],
});

//获取工序
const getProcess = (query: string) => {
	getAllProcess({
		ProcessName: query,
	}).then((res: any) => {
		if (res.code == 0) {
			processList.value = res.data;
		}
	});
};
const changeProcess = (val: any) => {
	queryRef2.value?.resetFields();
	materialShow.value = true;
	locationShow.value = true;
	dataForm.processCode = val.processCode;
	dataForm.processName = val.processName;
	dataForm.processid = val.id;
	isWarpBandShow.value = dataForm.processCode == 'DR';
	isCurrentLocationShow.value = dataForm.processCode != 'YH' && dataForm.processCode != 'FS';
};

//获取产线
const getProductionline = (query: string) => {
	getAllProductionlineByProcess({
		ProductionlineCode: query,
		Processid: dataForm.processid,
	}).then((res: any) => {
		if (res.code == 0) {
			Productionlinelist.value = res.data;
		}
	});
};
const changeProductionLine = (val: any) => {
	dataForm.productionLineCode = val.productionLineCode;
	dataForm.productionLineName = val.productionLineName;
	dataForm.productionLinId = val.id;
	if (
		dataForm.productionLineCode == 'ShutDownLine' ||
		dataForm.productionLineCode == 'CommissioningLine' ||
		dataForm.productionLineCode == 'WPCMainMixedLine' ||
		dataForm.productionLineCode == 'LVTMainMixedLine'
	) {
		materialShow.value = false;
		locationShow.value = true;
	} else if (dataForm.productionLineCode == 'SmallMaterialMixedLine') {
		materialShow.value = false;
		locationShow.value = false;
		try {
			getBaseData({
				processCode: dataForm.processCode,
				lineCode: dataForm.productionLineCode,
			}).then((res: any) => {
				if (res.code == 200) {
					smallDatalist.value = res.result;
				}
			});
		} catch (err: any) {
			useMessage().error(err.msg);
		}
	} else {
		materialShow.value = true;
		locationShow.value = true;
	}
};

//获取库位
const getLocation = () => {
	getProcessLocationByPrdLineId({
		Id: dataForm.productionLinId,
		Current: '1',
		IsPD: true,
		Size: '999',
	}).then((res: any) => {
		if (res.code == 0) {
			LocationList.value = res.data.records;
		}
	});
};
const changeLocation = (val: any) => {
	dataForm.locationCode = val.locationCode;
	dataForm.locationName = val.locationName;
	if (
		dataForm.productionLineCode == 'ShutDownLine' ||
		dataForm.productionLineCode == 'CommissioningLine' ||
		dataForm.productionLineCode == 'WPCMainMixedLine' ||
		dataForm.productionLineCode == 'LVTMainMixedLine'
	) {
		try {
			getBaseData({
				processCode: dataForm.processCode,
				lineCode: dataForm.productionLineCode,
				locationCode: dataForm.locationCode,
			}).then((res: any) => {
				if (res.code == 200) {
					otherDatalist.value = res.result;
				}
			});
		} catch (err: any) {
			useMessage().error(err.msg);
		}
	} else if (dataForm.productionLineCode == 'BigMaterialLine') {
		try {
			getBaseData({
				processCode: dataForm.processCode,
				lineCode: dataForm.productionLineCode,
				locationCode: dataForm.locationCode,
			}).then((res: any) => {
				if (res.code == 200) {
					console.log(res.result);
					dataForm.locationName = res.result[0].locationName;
					dataForm.materialCode = res.result[0].materialCode;
					dataForm.materialName = res.result[0].materialName;
					dataForm.unit = res.result[0].prdUnit;
				}
			});
		} catch (err: any) {
			useMessage().error(err.msg);
		}
	}
};

//获取物料
const getMaterial = (query: string) => {
	getAllMaterialsForNameOrCode({
		MaterialCode: query,
	}).then((res: any) => {
		if (res.code == 0) {
			materialList.value = res.data;
		}
	});
};
const changeMaterial = (val: any) => {
	console.log("changeMaterial",val);
	if(val){
		dataForm.materialCode = val.materialCode;
		dataForm.materialName = val.materialName;
	}else{
		dataForm.materialCode = '';
		dataForm.materialName = '';
	}
};

//操作类型
const changeOperationType = (val: any) => {
	dataForm.operationType = val.itemCode;
};

//操作描述
const changeOperationDescription = (val: any) => {
	dataForm.operationDescription = val.itemText;
};

//生成随机id
const generateRandomNum = () => {
	const timestamp = new Date().getTime();
	const randomNum = uuid();
	return timestamp.toString() + '-' + randomNum.toString();
};
const uuid = () => {
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
		var r = (Math.random() * 16) | 0,
			v = c == 'x' ? r : (r & 0x3) | 0x8;
		return v.toString(16);
	});
};

//添加
const addData = (query: any) => {
	Promise.all([queryRef.value.validate(), queryRef2.value.validate()])
		.then(() => {
			if (new Date(dataForm.endTime) <= new Date(dataForm.startTime)) {
				useMessage().error(t('iot.endtimeNotLessThanStarttime'));
				return;
			}
			var uuidStr = uuid();
			if (
				dataForm.productionLineCode == 'ShutDownLine' ||
				dataForm.productionLineCode == 'CommissioningLine' ||
				dataForm.productionLineCode == 'WPCMainMixedLine' ||
				dataForm.productionLineCode == 'LVTMainMixedLine'
			) {
				otherDatalist.value.forEach((element) => {
					const newDataForm = JSON.parse(JSON.stringify(dataForm));
					newDataForm.id = generateRandomNum();
					newDataForm.materialCode = element.materialCode;
					newDataForm.materialName = element.materialName;
					newDataForm.unit = element.prdUnit;
					newDataForm.qty = element.qty;
					newDataForm.uuid = uuidStr;
					state.dataList?.push(newDataForm);
				});
			} else if (dataForm.productionLineCode == 'SmallMaterialMixedLine') {
				smallDatalist.value.forEach((element) => {
					const newDataForm = JSON.parse(JSON.stringify(dataForm));
					newDataForm.id = generateRandomNum();
					newDataForm.locationCode = element.locationCode;
					newDataForm.locationName = element.locationName;
					newDataForm.materialCode = element.materialCode;
					newDataForm.materialName = element.materialName;
					newDataForm.unit = element.prdUnit;
					newDataForm.qty = element.qty;
					newDataForm.uuid = uuidStr;
					state.dataList?.push(newDataForm);
				});
			} else {
				// 深拷贝对象
				dataForm.id = generateRandomNum();
				dataForm.uuid = uuidStr;
				var newData = JSON.parse(JSON.stringify(dataForm));
				state.dataList?.push(newData);
			}
		})
		.catch((error) => {
			console.log(error);
			if (error.error) {
				useMessage().error(error.error);
			}
		});
};

// 清空搜索条件
const resetQuery = () => {
	// 清空搜索条件
	queryRef.value?.resetFields();
	queryRef2.value?.resetFields();
	materialShow.value = true;
	locationShow.value = true;
	smallDatalist.value = [];
	otherDatalist.value = [];
	isCurrentLocation.value = false;
	isCurrentLocationShow.value = true;
	isWarpBandShow.value = true;
	isWarp.value = false;
	isBand.value = false;
};

// 多选变量
const selectObjs = ref([]) as any;
const multiple = ref(true);
// 多选事件
const selectionChangeHandle = (objs) => {
	selectObjs.value = objs;
	multiple.value = !objs.length;
};
// 删除操作
const handleDelete = async (ids: Array<number>) => {
	if (ids?.length === 0) {
		return useMessage().warning(t('basProcess.selectDelete'));
	}

	try {
		selectObjs.value.forEach((element) => {
			var index = state.dataList?.map((m) => m.id).indexOf(element.id);
			if (index !== -1) {
				state.dataList.splice(index, 1);
			}
		});
		useMessage().success(t('basProcess.deleteSuccess'));
	} catch (err: any) {
		useMessage().error(t('basProcess.deleteFaild') + err.msg);
	}
};

// 提交
const save = async () => {
	try {
		if (selectObjs.value.length <= 0) {
			useMessage().error(t('iot.inputDataIsEmpty'));
			return;
		}
		queryRef.value?.resetFields();
		const inputList = ref([]) as any;
		selectObjs.value.forEach((element) => {
			var inputdata = {
				batch_no: element.lotNo,
				batch_count: element.lotNo,
				production_line_code: element.productionLineCode,
				production_line_name: element.productionLineName,
				process_code: element.processCode,
				process_name: element.processName,
				location_code: element.locationCode,
				location_name: element.locationName,
				location_type: element.locationTypeName,
				material_code: element.materialCode,
				material_name: element.materialName,
				qty: element.qty,
				produce_start_time: element.startTime,
				produce_end_time: element.endTime,
				carton_no: element.palletNumber,
				operate_type: element.operationType,
				operate_desc: element.operationDescription,
				prd_unit: element.unit,
				uuid: element.uuid,
				is_current_location: isCurrentLocation.value ? 'Y' : 'N',
				is_wrap: isWarp.value ? 'Y' : 'N',
				is_band: isBand.value ? 'Y' : 'N',
			};
			inputList.value.push(inputdata);
		});
		console.log(inputList.value);
		await iOTOutputDataEntry({
			lstTransferDto: inputList.value,
		}).then((res: any) => {
			if (res.code == 200) {
				selectObjs.value.forEach((element) => {
					var index = state.dataList?.map((m) => m.id).indexOf(element.id);
					if (index !== -1) {
						state.dataList.splice(index, 1);
					}
				});
				useMessage().success(t('basProcess.submitSuccess'));
			} else {
				useMessage().error(res.message);
			}
		});
	} catch (err: any) {
		useMessage().error(err.msg);
	} finally {
	}
};

const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state);
</script>
